﻿namespace OleDbDAL.Processing
{
    using DBUtility;
    using IDal.Processing;
    using Model.Processing;
    using System;
    using System.Data;
    using System.Text;

    public class TeaPackagingApp : ITeaPackaging
    {
        private string dbname = "Systems";

        public void Add(TeaPackagingEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("insert into T_TeaPackaging(");
            builder.Append("ChainNum,FormulaId,PackagingNum,TeaCommLots,TeaCommId,TeaCommName,TeaPackagingNum,TeaPackagingMoney,TeaPackagingInputDlId,IsUseFormula,ProcessingMan,ProcessingTime,IsCheck,CheckMan,CheckTime,PackagingStatic,Remark");
            builder.Append(")");
            builder.Append(" values (");
            builder.Append("" + model.ChainNum + ",");
            builder.Append("" + model.FormulaId + ",");
            builder.Append("'" + model.PackagingNum + "',");
            builder.Append("'" + model.TeaCommLots + "',");
            builder.Append("" + model.TeaCommId + ",");
            builder.Append("'" + model.TeaCommName + "',");
            builder.Append("" + model.TeaPackagingNum + ",");
            builder.Append("'" + model.TeaPackagingMoney + "',");
            builder.Append("" + model.TeaPackagingInputDlId + ",");
            builder.Append("" + model.IsUseFormula + ",");
            builder.Append("" + model.ProcessingMan + ",");
            builder.Append("'" + model.ProcessingTime + "',");
            builder.Append("" + model.IsCheck + ",");
            builder.Append("" + model.CheckMan + ",");
            builder.Append("'" + model.CheckTime + "',");
            builder.Append("" + model.PackagingStatic + ",");
            builder.Append("'" + model.Remark + "'");
            builder.Append(")");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Delete(int PackagingId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("delete from T_TeaPackaging ");
            builder.Append(" where PackagingId=" + PackagingId);
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public DataTable GetList(string strWhere)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_TeaPackaging ");
            if (strWhere.Trim() != "")
            {
                builder.Append(" where " + strWhere);
            }
            builder.Append(" order by PackagingId ");
            return DbHelperOledb.Query(this.dbname, builder.ToString());
        }

        public int GetMaxId(string swhere)
        {
            return DbHelperOledb.GetMaxID(this.dbname, "PackagingId", "T_TeaPackaging", swhere);
        }

        public TeaPackagingEnt GetModel(int PackagingId)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("select PackagingId,ChainNum,FormulaId,PackagingNum,TeaCommLots,TeaCommId,TeaCommName,TeaPackagingNum,TeaPackagingMoney,TeaPackagingInputDlId,IsUseFormula,ProcessingMan,ProcessingTime,IsCheck,CheckMan,CheckTime,PackagingStatic,Remark from T_TeaPackaging ");
            builder.Append(" where PackagingId=" + PackagingId);
            TeaPackagingEnt ent = new TeaPackagingEnt();
            DataTable table = DbHelperOledb.Query(this.dbname, builder.ToString());
            ent.PackagingId = PackagingId;
            if (table.Rows.Count > 0)
            {
                if (table.Rows[0]["ChainNum"].ToString() != "")
                {
                    ent.ChainNum = int.Parse(table.Rows[0]["ChainNum"].ToString());
                }
                if (table.Rows[0]["FormulaId"].ToString() != "")
                {
                    ent.FormulaId = int.Parse(table.Rows[0]["FormulaId"].ToString());
                }
                ent.PackagingNum = table.Rows[0]["PackagingNum"].ToString();
                ent.TeaCommLots = table.Rows[0]["TeaCommLots"].ToString();
                if (table.Rows[0]["TeaCommId"].ToString() != "")
                {
                    ent.TeaCommId = int.Parse(table.Rows[0]["TeaCommId"].ToString());
                }
                ent.TeaCommName = table.Rows[0]["TeaCommName"].ToString();
                if (table.Rows[0]["TeaPackagingNum"].ToString() != "")
                {
                    ent.TeaPackagingNum = decimal.Parse(table.Rows[0]["TeaPackagingNum"].ToString());
                }
                ent.TeaPackagingMoney = table.Rows[0]["TeaPackagingMoney"].ToString();
                if (table.Rows[0]["TeaPackagingInputDlId"].ToString() != "")
                {
                    ent.TeaPackagingInputDlId = int.Parse(table.Rows[0]["TeaPackagingInputDlId"].ToString());
                }
                if (table.Rows[0]["IsUseFormula"].ToString() != "")
                {
                    ent.IsUseFormula = int.Parse(table.Rows[0]["IsUseFormula"].ToString());
                }
                if (table.Rows[0]["ProcessingMan"].ToString() != "")
                {
                    ent.ProcessingMan = int.Parse(table.Rows[0]["ProcessingMan"].ToString());
                }
                if (table.Rows[0]["ProcessingTime"].ToString() != "")
                {
                    ent.ProcessingTime = DateTime.Parse(table.Rows[0]["ProcessingTime"].ToString());
                }
                if (table.Rows[0]["IsCheck"].ToString() != "")
                {
                    ent.IsCheck = int.Parse(table.Rows[0]["IsCheck"].ToString());
                }
                if (table.Rows[0]["CheckMan"].ToString() != "")
                {
                    ent.CheckMan = int.Parse(table.Rows[0]["CheckMan"].ToString());
                }
                if (table.Rows[0]["CheckTime"].ToString() != "")
                {
                    ent.CheckTime = DateTime.Parse(table.Rows[0]["CheckTime"].ToString());
                }
                if (table.Rows[0]["PackagingStatic"].ToString() != "")
                {
                    ent.PackagingStatic = int.Parse(table.Rows[0]["PackagingStatic"].ToString());
                }
                ent.Remark = table.Rows[0]["Remark"].ToString();
                return ent;
            }
            return null;
        }

        public DataTable GetPageList(int PageSize, int PageIndex, string strWhere)
        {
            string orderString = "";
            int pageCount = 0;
            int recordCount = 0;
            StringBuilder builder = new StringBuilder();
            builder.Append("select * from T_TeaPackaging ");
            return DbHelperOledb.ExecutePager(this.dbname, PageIndex, PageSize, "", builder.ToString(), strWhere, orderString, out pageCount, out recordCount, "PackagingId");
        }

        public void IsCheck(TeaPackagingEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_TeaPackaging set ");
            builder.Append("PackagingStatic=" + model.PackagingStatic + ",");
            builder.Append("IsCheck=" + model.IsCheck + ",");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "'");
            builder.Append(" where PackagingId=" + model.PackagingId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }

        public void Update(TeaPackagingEnt model)
        {
            StringBuilder builder = new StringBuilder();
            builder.Append("update T_TeaPackaging set ");
            builder.Append("ChainNum=" + model.ChainNum + ",");
            builder.Append("FormulaId=" + model.FormulaId + ",");
            builder.Append("PackagingNum='" + model.PackagingNum + "',");
            builder.Append("TeaCommLots='" + model.TeaCommLots + "',");
            builder.Append("TeaCommId=" + model.TeaCommId + ",");
            builder.Append("TeaCommName='" + model.TeaCommName + "',");
            builder.Append("TeaPackagingNum=" + model.TeaPackagingNum + ",");
            builder.Append("TeaPackagingMoney='" + model.TeaPackagingMoney + "',");
            builder.Append("TeaPackagingInputDlId=" + model.TeaPackagingInputDlId + ",");
            builder.Append("IsUseFormula=" + model.IsUseFormula + ",");
            builder.Append("ProcessingMan=" + model.ProcessingMan + ",");
            builder.Append("ProcessingTime='" + model.ProcessingTime + "',");
            builder.Append("IsCheck=" + model.IsCheck + ",");
            builder.Append("CheckMan=" + model.CheckMan + ",");
            builder.Append("CheckTime='" + model.CheckTime + "',");
            builder.Append("PackagingStatic=" + model.PackagingStatic + ",");
            builder.Append("Remark='" + model.Remark + "'");
            builder.Append(" where PackagingId=" + model.PackagingId + "");
            DbHelperOledb.ExecuteSql(this.dbname, builder.ToString());
        }
    }
}

